<!DOCTYPE HTML>
<html lang="fr">
<head>
	<title><?php echo CHtml::encode($this->pageTitle); ?></title>

	<meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

	<!-- Bootstrap -->
	<link href="<?php echo Yii::app()->request->baseUrl; ?>/css/bootstrap<?php echo (($this->skin <> '') ? "-".$this->skin : "");?>.min.css" rel="stylesheet" media="screen">
	<link rel="stylesheet" href="<?php echo Yii::app()->request->baseUrl; ?>/css/font-awesome/css/font-awesome.min.css">
	<link href="<?php echo Yii::app()->request->baseUrl; ?>/css/bootstrap-datepicker.css" rel="stylesheet" media="screen">
	<link href="<?php echo Yii::app()->request->baseUrl; ?>/css/typeahead.css" rel="stylesheet" media="screen">
	
	<!-- Fonts -->
	<link href='http://fonts.googleapis.com/css?family=Oxygen' rel='stylesheet' type='text/css'>
	
	<!-- Multiselect -->
	<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/bootstrap-multiselect.js"></script>
	<link rel="stylesheet" href="<?php echo Yii::app()->request->baseUrl; ?>/css/bootstrap-multiselect.css" type="text/css"/>

	<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
	<!--[if lt IE 9]>
	<script src="../../assets/js/html5shiv.js"></script>
	<script src="../../assets/js/respond.min.js"></script>
	<![endif]-->
	<link href="<?php echo Yii::app()->request->baseUrl; ?>/css/selavenir.css" rel="stylesheet" media="screen">
</head>

<body>

	<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
		<div class="container">
			<!-- Brand and toggle get grouped for better mobile display -->
			<div class="navbar-header">
				<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
					<span class="sr-only">Toggle navigation</span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</button>
			</div>

			<!-- Collect the nav links, forms, and other content for toggling -->	
			<div class="collapse navbar-collapse navbar-ex1-collapse">
				<?php echo CHtml::link('SELAVENIR',array('site/index'),array("class"=>"navbar-brand"));?>
							
				<ul class="nav navbar-nav navbar-right">
					<?php if (!Yii::app()->user->isGuest) {?>
						<?php echo "<li id=\"menu_permanences\" data-toggle=\"tooltip\" data-placement=\"bottom\" data-container=\"body\" data-title=\"Voir le calendrier des permanences\"" . (($this->route == "seliste/permanence") ? " class='active'>" : ">") . CHtml::link('<span class="fa fa-calendar fa-lg fa-fw"></span>',array('seliste/permanence')) . "</li>";?>		
						<?php echo "<li id=\"menu_selistes\" data-toggle=\"tooltip\" data-placement=\"bottom\" data-container=\"body\" data-title=\"Voir les sélistes\"" . (($this->route == "seliste/liste") ? " class='active'>" : ">") . CHtml::link('<span class="fa fa-users fa-lg fa-fw"></span>',array('seliste/liste')) . "</li>";?>		
						<?php echo "<li id=\"menu_catalogue\" data-toggle=\"tooltip\" data-placement=\"bottom\" data-container=\"body\" data-title=\"Voir le catalogue\"" . (($this->id == "grains") ? " class='active'>" : ">") . CHtml::link('<span class="fa fa-book fa-lg fa-fw"></span>',array('grain/liste')) . "</li>";?>
						<?php 
						$actions_compte = array("seliste/compte","seliste/update_compte","seliste/update_compte_pass","seliste/update_compte_grains","demande/compte","offre/compte");
						$actions_moncompte = array("seliste/compte","seliste/update_compte","seliste/update_compte_pass",);
						$actions_mail = array("seliste/mailbox","seliste/mail","seliste/newmail","seliste/smail","seliste/sentmail");
						$unread = '';
						$nbunread = Seliste::model()->getNbUnread();
						if ($nbunread) $unread = ' <span class="badge">' . $nbunread . '</span>';
						?>
						<li id="menu_compte" data-toggle="tooltip" data-placement="bottom" data-container="body" data-title="Mon compte" class="dropdown
							<?php 
							if (in_array($this->route,$actions_mail) || in_array($this->route,$actions_compte)) echo " active";
							?>
							">
							<a id="acompte" href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="fa fa-user fa-fw fa-lg"></span> <?php echo Yii::app()->user->name;?><?php echo $unread;?><b class="caret"></b></a>
							<ul class="dropdown-menu">
								<?php
								echo "<li" . (in_array($this->route,$actions_moncompte) ? " class='active'>" : ">") . CHtml::link('<span class="fa fa-sliders fa-lg fa-fw"></span> Mon compte',array('seliste/compte')) . "</li>";
								echo "<li id=\"menu_mailbox\"";
								if (in_array($this->route,$actions_mail)) echo " class=\"active\"";
								echo ">" . CHtml::link('<span class="fa fa-envelope fa-lg fa-fw"></span> Ma boîte de réception'.$unread,array('seliste/mailbox')) . "</li>";
								echo "<li" . (($this->route == "seliste/update_compte_grains") ? " class='active'>" : ">") . CHtml::link('<span class="fa fa-list fa-lg fa-fw"></span> Mes grains',array('seliste/update_compte_grains')) . "</li>";
								$offres = '';
								$nboffres = Offre::model()->getNbOffres();
								if ($nboffres) $offres = ' <span class="badge pull-right">' . $nboffres . '</span>';
								echo "<li" . (($this->route == "offre/compte") ? " class='active'>" : ">") . CHtml::link('<span class="fa fa-reply fa-lg fa-fw"></span> Mes offres'.$offres,array('offre/compte')) . "</li>";
								$demandes = '';
								$nbdemandes = Demande::model()->getNbDemandes();
								if ($nbdemandes) $demandes = ' <span class="badge pull-right">' . $nbdemandes . '</span>';
								echo "<li" . (($this->route == "demande/compte") ? " class='active'>" : ">") . CHtml::link('<span class="fa fa-question fa-lg fa-fw"></span> Mes demandes'.$demandes,array('demande/compte')) . "</li>";
								//echo "<li" . (($this->route == "echange/compte") ? " class='active'>" : ">") . CHtml::link('Mes échanges',array('echange/compte')) . "</li>";
								echo "<li>" . CHtml::link('<span class="fa fa-sign-out fa-lg fa-fw"></span> Déconnexion',array('site/logout')) . "</li>";
								?>
							</ul>
						</li>
						<?php if (Yii::app()->user->admin == 1) echo "<li id=\"menu_admin\" data-toggle=\"tooltip\" data-placement=\"bottom\" data-container=\"body\" data-title=\"Administration\"" . (($this->route == "site/admin") ? " class='active'>" : ">") . CHtml::link('<span class="fa fa-cogs fa-lg fa-fw"></span>',array('site/admin')) . "</li>";?>
						<?php Yii::app()->getClientScript()->registerScript('tooltip_menu', "$('#menu_permanences').tooltip();$('#menu_selistes').tooltip();$('#menu_catalogue').tooltip();$('#menu_mailbox').tooltip();$('#menu_compte').tooltip();$('#menu_admin').tooltip();",CClientScript::POS_READY);?>
						<?php 
						Yii::app()->getClientScript()->registerScript("tooltip_close","
							$('#menu_compte').on('show.bs.dropdown', function () {
							  	$('#menu_compte').tooltip('destroy');
							});
							$('#menu_compte').on('hidden.bs.dropdown', function () {
							  	$('#menu_compte').tooltip();
							});
						",CClientScript::POS_READY);
						?>
					<?php } ?>	
				</ul>
				<?php if (($this->route <> "site/index") && (!Yii::app()->user->isGuest)) {?> 
				<ul class="nav navbar-nav navbar-right" id="navbar-demande">
					<?php echo "<li id=\"menu_demande\" data-toggle=\"tooltip\" data-placement=\"bottom\" data-container=\"body\" data-title=\"Faire une demande\"" . (($this->route == "demande/depot") ? " class='active'>" : ">") . CHtml::link('<span class="fa fa-lg fa-fw fa-question"></span>',array('demande/depot')) . "</li>";?>		
					<?php echo "<li id=\"menu_demande_rapide\" data-toggle=\"tooltip\" data-placement=\"bottom\" data-container=\"body\" data-title=\"Faire une demande rapide\"" . (($this->route == "demande/demanderapide") ? " class='active'>" : ">") . CHtml::link('<span class="fa fa-lg fa-fw fa-flash"></span>',array('demande/demanderapide')) . "</li>";?>		
					<?php echo "<li id=\"menu_offre_rapide\" data-toggle=\"tooltip\" data-placement=\"bottom\" data-container=\"body\" data-title=\"Faire une offre rapide\"" . (($this->route == "offre/offrerapide") ? " class='active'>" : ">") . CHtml::link('<span class="fa fa-lg fa-fw fa-gift"></span>',array('offre/offrerapide')) . "</li>";?>
					<?php Yii::app()->getClientScript()->registerScript('tooltip_menudemande', "$('#menu_demande').tooltip();$('#menu_demande_rapide').tooltip();$('#menu_offre_rapide').tooltip();",CClientScript::POS_READY);?>								
				</ul>
				<?php }?>
				
			</div><!-- /.navbar-collapse -->
		</dir>
	</nav>
				
	<?php echo $content;?>
		
	<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
	<?php 
	$cs = Yii::app()->getClientScript();
	$cs->registerCoreScript('jquery');
	?>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="<?php echo Yii::app()->request->baseUrl; ?>/js/bootstrap.min.js"></script>
	<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/bootstrap-datepicker.js"></script>
	<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/typeahead.bundle.min.js"></script>
	<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/handlebars-v1.3.0.js"></script>
	<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/locales/bootstrap-datepicker.fr.js" charset="UTF-8"></script>
	<?php 
	if ($this->route <> "seliste/update_grains") {
	?>
	<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/admin.js"></script>
	<?php 
	}
	?>
</body>
</html>